<?php

namespace oa\models;

use Yii;

class Menu extends BaseModel
{

    const SCENARIO_ADD     = 'add';
    const SCENARIO_EDIT    = 'edit';
    const SCENARIO_REMOVE  = 'remove';
    const SCENARIO_DISABLE = 'disable';
    const SCENARIO_ENABLE  = 'enable';

    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'menu';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['pid', 'sort', 'is_target', 'is_show', 'is_test', 'status', 'aid', 'updated_at', 'created_at'], 'integer'],
            [['name'], 'required'],
            [['actions'], 'string'],
            [['name'], 'string', 'max' => 20],
            [['url'], 'string', 'max' => 128],
            [['remark'], 'string', 'max' => 100],
            [['icon'], 'string', 'max' => 32],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'pid' => 'Pid',
            'name' => 'Name',
            'url' => 'Url',
            'actions' => 'Actions',
            'remark' => 'Remark',
            'icon' => 'Icon',
            'sort' => 'Sort',
            'is_target' => 'Is Target',
            'is_show' => 'Is Show',
            'is_test' => 'Is Test',
            'status' => 'Status',
            'aid' => 'Aid',
            'updated_at' => 'Updated At',
            'created_at' => 'Created At',
        ];
    }

    public function behaviors()
    {
        return [
            $this->autosaveTimestamp(),
        ];
    }

    public function scenarios()
    {
        $scenarios = parent::scenarios();
        $scenarios[self::SCENARIO_ADD] = ['pid', 'name', 'url', 'actions', 'remark', 'icon', 'sort',  'is_show', 'is_target', 'is_test', 'status', 'aid'];
        $scenarios[self::SCENARIO_EDIT] = ['pid', 'name', 'url', 'actions', 'remark', 'icon', 'sort',  'is_show', 'is_target', 'is_test', 'status', 'aid'];
        $scenarios[self::SCENARIO_REMOVE] = ['status'];
        $scenarios[self::SCENARIO_DISABLE] = ['status'];
        $scenarios[self::SCENARIO_ENABLE] = ['status'];
        return $scenarios;
    }
}
